$(function(){
    //初始化
	$('#dowebok').fullpage({
		sectionsColor: ['#F2F2F2', '#F2F2F2']
	});
	//欢迎页鼠标移入样式
	$(".mainNav a").hover(function(){
		$(this).find('.img').css('display','none');
		$(this).find('.imghover').css('display','block');
		$(this).find('dd').css('color','#24956D');
	},function(){
		$(this).find('.img').css('display','block');
		$(this).find('.imghover').css('display','none');
		$(this).find('dd').css('color','#666');
	});
	//欢迎页下滑查看更多点击事件
	$('.updownMorebox').click(function(){
		$.fn.fullpage.moveSectionDown();
	});
	//注册表单提交
	$("#registerSub").click(function (){
	    var member_name = $("#register input[name='member_name']").val();
	    var phone = $("#register input[name='phone']").val();
	    var email = $("#register input[name='email']").val();
	    var password = $("#register input[name='password']").val();
	    var confirm_password = $("#register input[name='confirm_password']").val();
	    var work_company = $("#register input[name='work_company']").val();
	    var post = $("#register input[name='post']").val();
	    var objective = $("#register textarea[name='objective']").val();
	    if (member_name == ''){
            alert('用户名不能为空');
            return false;
        }
        if (phone == ''){
            alert('手机号不能为空');
            return false;
        }
        if (email == ''){
            alert('电子邮箱不能为空');
            return false;
        }
        if (password == ''){
            alert('密码不能为空');
            return false;
        }
        if (confirm_password == ''){
            alert('确认密码不能为空');
            return false;
        }
        if (work_company == ''){
            alert('工作单位能为空');
            return false;
        }
        if (post == ''){
            alert('职务不能为空');
            return false;
        }
        if (objective == ''){
            alert('注册目的不能为空');
            return false;
        }
        //验证手机号
        var myreg = /^1[0-9]{10}$/;
        if (!myreg.test(phone)) {
            console.log(phone);
            alert('手机号格式不正确');
            return false;
        }
        if (password !== confirm_password){
	        alert('两次密码不正确');
            return false;
        }
	    $.ajax({
            url:'register',
            data :{
                'member_name':member_name,
                'phone':phone,
                'email':email,
                'password':password,
                'confirm_password':confirm_password,
                'work_company':work_company,
                'post':post,
                'objective':objective
            },
            type:'POST',
            success:function (res){
                alert(res.msg);
                if (res.code == 200){
                    window.location.href='/';
                }
            },
            error:function (e){
                console.log(e);
            }
        });
    });
	$('#loginSub').click(function (){
        var member_name = $("#popup input[name='member_name']").val();
        var password = $("#popup input[name='password']").val();
        if (member_name == ''){
            alert('用户名不能为空');
            return false;
        }
        if (password == ''){
            alert('密码不能为空');
            return false;
        }
        $.ajax({
            url:'login',
            data :{
                'member_name':member_name,
                'password':password,
            },
            type:'POST',
            success:function (res){
                console.log(res);
                alert(res.msg);
                if (res.code == 200){
                    window.location.href='/';
                }
            }
        });
    });
	$("#loginOut").click(function (){
        $.ajax({
            url:'loginOut',
            type:'POST',
            success:function (){
                alert('退出成功');
                window.location.href='/';
            }
        });
    });

});
